package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class JDBCDemo6 {
    public static void main(String[] args) {
        System.out.println("欢迎登录");
        try (Connection connection = DBUtil.getConnection();){
            Scanner scanner = new Scanner(System.in);
            Statement statement = connection.createStatement();
            System.out.println("请输入用户名");
            String username = scanner.nextLine();
            System.out.println("请输密码");
            String password = scanner.nextLine();
            String sql = "SELECT username ,password,nickname FROM userinfo WHERE username= '"+username+"' AND password ='"+password+"' ";
            ResultSet rs = statement.executeQuery(sql);
            if(rs.next()){
                String nickname = rs.getString("nickname");
                System.out.println("登录成功，欢迎回来"+nickname);
            }else {
                System.out.println("用户名或密码错误，登录失败");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
